<template>
	<view class="goods-list">
		<view v-for="(item,index) in goodsList" :key="index" @click="gotoDetail(item)">
			<my-goods :item="item"></my-goods>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				queryInfo: {
					query: '',
					cid: '',
					pagenum: 1,
					pagesize: 20
				},
				goodsList: [],
				total: 0,
				defaultPic: '',
				isloading: false
			}
		},
		methods: {
			async getGoodsList(callback) {
				this.isloading = true
				const {
					data: res
				} = await uni.$http.get('api/public/v1/goods/search', this.queryInfo)
				if (res.meta.status !== 200) return uni.$showMsg()
				callback && callback()
				uni.$showMsg(res.meta.msg)
				this.goodsList = [...this.goodsList, ...res.message.goods]
				this.pagenum = res.message.pagenum
				this.total = res.message.total
				this.isloading = false
			},
			gotoDetail(item) {
				uni.navigateTo({
					url: '/subpkg/goods_detail/goods_detail?goods_id=' + item.goods_id
				})
			}
		},
		onLoad(options) {
			this.queryInfo.query = options.query || ''
			this.queryInfo.cid = options.cid || ''
			this.getGoodsList()
		},
		onReachBottom() {
			console.log(this.queryInfo.pagesize)
			console.log(this.queryInfo.pagenum)
			console.log(this.total)
			if (this.queryInfo.pagesize * this.queryInfo.pagenum >= this.total) return uni.$showMsg('加载完毕')
			if (this.isloading) return
			this.queryInfo.pagenum += 1
			this.getGoodsList()
		},
		onPullDownRefresh() {
			this.goodsList = []
			this.queryInfo.pagenum = 1
			this.total = 0
			this.isloading = false
			this.getGoodsList(() => {
				uni.stopPullDownRefresh()
			})
		}
	}
</script>

<style lang="scss">

</style>
